<html>
    <head>
        <title>Mike's Auto Parts - Order Results</title>
    </head>
    <body>
        <h1>Mike's Auto Parts</h1>
        <h2>Order Results</h2>
        <?php
        // create short variable names
        $tireqty = $_POST['tireqty'];
        $oilqty = $_POST['oilqty'];
        $sparkqty = $_POST['sparkqty'];
        $find = $_POST['find'];
        $address = $_POST['address'];
        $totalqty = 0;
        $totalqty = $tireqty + $oilqty + $sparkqty;
        if ($totalqty == 0) {
            echo "You did not order anything on the previous page!<br />
                <p><a href='index.html'>Home</a></p></body></html>";
            exit;
        }
        echo "<p>Order processed at ".date('H:i, jS F Y')."</p>";
        echo '<p>Your order is as follows:</p>';
        echo $tireqty.' tires<br />';
        echo $oilqty.' bottles of oil<br />';
        echo $sparkqty.' spark plugs<br />';
        /*
        $totalqty = 0;
        $totalqty = $tireqty + $oilqty + $sparkqty;
        */
        echo "<p></p>Items ordered: ".$totalqty."<br />";
        $totalamount = 0.00;
        // define constants
        define('TIREPRICE', 100);
        define('OILPRICE', 10);
        define('SPARKPRICE', 4);
        // calculate totalamount
        $totalamount = $tireqty * TIREPRICE
                    + $oilqty * OILPRICE
                    + $sparkqty * SPARKPRICE;

        echo "Subtotal: $".number_format($totalamount,2)."<br />";

        $taxrate = 0.21; // local sales tax is 21%
        $totalamount = $totalamount * (1 + $taxrate);
        echo "Total including tax: $".number_format($totalamount,2)."<br />";
        // referral done by...
        switch ($find) {
            case "a":
                echo "<p>Regular customer.</p>";
                break;
            case "b":
                echo "<p>Customer referred by TV advert.</p>";
                break;
            case "c":
                echo "<p>Customer referred by phone directory.</p>";
                break;
            case "d":
                echo "<p>Customer referred by word of mouth.</p>";
                break;
            default :
                echo "<p>We do not know how this customer found us.</p>";
                break;
            }
        @ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab');
        if (!$fp){
            echo "<p><strong> Your order could not be processed at this time.
                Please try again later.</strong></p><a href='index.html'>Home</a></body></html>";
            exit;
        }
        ?>
    </body>
</html>